<?php

/**
 * @Author: Mr.Mao
 * @Date:   2021-05-29 10:25:54
 * @Last Modified by:   Mr.Mao
 * @Last Modified time: 2021-05-31 11:39:15
 */
namespace app\mainadmin\controller;
use app\AdminController;
use app\mainadmin\model\StorageModel;
use app\mainadmin\model\SettingsModel;
/**
 * 存储配置
 * Class Index
 * @package app\store\controller
 */
class Storage extends AdminController
{	
	/*------------------------------------------------------ */
	//-- 优先执行
	/*------------------------------------------------------ */
	public function initialize(){
        parent::initialize();
        $this->Model = new StorageModel();		
    }

    public function index()
    {
    	$data = $this->Model->getRows();
    	$this->assign('uploadType',settings('uploadType'));
    	$this->assign('list',$data);
    	return $this->fetch('index');
    }

    public function save()
    {
    	$id = input('supplier',0,'intval');
    	$res =(new SettingsModel)->editSave(['uploadType'=>$id]);
		if ($res == false) return $this->error();
		if ($id <= 0) return $this->success('保存成功');
		$def_config = input('def_config');
		$data = [];
		$data['config'] = json_encode($def_config);
		$data['update_time'] = time();
		$res = $this->Model->where('id',$id)->update($data);
		if ($res <= 0) return $this->error();
		return $this->success('保存成功');
    }
}